home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / mktil16a.zip / HEADERS.ZIP / MOUSE.H < prev    next >
C/C++ Source or Header  |  1994-09-16  |  7KB  |  276 lines

  1. #ifndef DOSH
  2.  #include <dos.h>
  3. #endif
  4.  
  5. #ifndef GRAPHH
  6.  #include <graph.h>
  7. #endif
  8.  
  9. #ifndef STDIOH
  10.  #include <stdio.h>
  11. #endif
  12.  
  13. #ifndef NORMAL
  14.  #define NORMAL 1
  15.  #define MASK 2
  16. #endif
  17.  
  18. #ifndef NO
  19.  #define NO 0
  20.  #define YES 1
  21. #endif
  22.  
  23. #define MOUSE_ON 1
  24. #define MOUSE_OFF 2
  25.  
  26. #define MOUSE_CURSOR_X_SIZE 16
  27. #define MOUSE_CURSOR_Y_SIZE 16
  28. #define MOUSE_CURSOR_SIZE MOUSE_CURSOR_X_SIZE*MOUSE_CURSOR_Y_SIZE
  29.  
  30. #define MOUSE_CLICK_DELAY 50 /* in milliseconds */
  31.  
  32. word mouse_x, mouse_y;
  33. byte mouse_1, mouse_2, mouse_3;
  34. word mouse_status;
  35. byte mouse_flag=OFF;
  36. byte mouse_click=NO;
  37.  
  38. word old_mouse_offset,
  39.      old_mouse_segment,
  40.      old_mouse_mask;
  41.  
  42. byte huge *mouse_cursor,
  43.       *mouse_background;
  44.  
  45. d_word old_mouse_timer, mouse_timer=0, max_mouse_timer=MOUSE_CLICK_DELAY;
  46.  
  47.  
  48. /****************************************************************************/
  49. /****************************************************************************/
  50. /****************************************************************************/
  51.  
  52. void set_mouse(short value)
  53. {
  54.  union REGS inregs, outregs;
  55.  
  56.  inregs.h.ah=0;
  57.  inregs.h.al=(char)value;
  58.  int86(0x33,&inregs,&outregs);
  59. }
  60.  
  61. /****************************************************************************/
  62. /****************************************************************************/
  63. /****************************************************************************/
  64.  
  65. void restrict_mouse(short x1,short y1,short x2,short y2)
  66. {
  67.  union REGS inregs, outregs;
  68.  
  69.  inregs.x.ax=7;                   // Set X limits
  70.  inregs.x.cx=x1*2;
  71.  inregs.x.dx=x2*2;
  72.  int86(0x33,&inregs,&outregs);
  73.  
  74.  inregs.x.ax=8;                   // Set Y limits
  75.  inregs.x.cx=y1;
  76.  inregs.x.dx=y2;
  77.  int86(0x33,&inregs,&outregs);
  78. }
  79.  
  80. /****************************************************************************/
  81. /****************************************************************************/
  82. /****************************************************************************/
  83.  
  84. void position_mouse(short x, short y)
  85. {
  86.  union REGS inregs, outregs;
  87.  
  88.  inregs.x.ax=4;                   // Move to X, Y
  89.  inregs.x.cx=x*2;
  90.  inregs.x.dx=y;
  91.  int86(0x33,&inregs,&outregs);
  92. }
  93.  
  94. /****************************************************************************/
  95. /****************************************************************************/
  96. /****************************************************************************/
  97.  
  98. void interrupt mouse_handler(void)
  99. {
  100.  union REGS inregs;
  101.  
  102.  _asm
  103.  {
  104.   push    ds
  105.  
  106.   mov     al,[palette_flag]
  107.   dec     al
  108.   jz      end
  109.  
  110.   mov     ax,3
  111.   int     0x33
  112.   shr     cx,1
  113.   mov     [mouse_x],cx
  114.   shl     cx,1
  115.   mov     [mouse_y],dx
  116.  
  117.   mov     ax,bx
  118.   mov     [mouse_status],bx
  119.   and     ax,0x0001
  120.   mov     [mouse_1],al
  121.  
  122.   and     ax,0x0002
  123.   mov     [mouse_3],al
  124.  
  125.   and     ax,0x0004
  126.   mov     [mouse_2],al
  127.  
  128.   mov     ax,4
  129.   int     0x33
  130.  
  131.   end:
  132.   pop     ds
  133.  }
  134. }
  135.  
  136. /****************************************************************************/
  137. /****************************************************************************/
  138. /****************************************************************************/
  139.  
  140. void install_mouse_handler(void)
  141. {
  142.  union REGS inregs, outregs;
  143.  struct SREGS segs;
  144.  
  145.  word func_off, func_seg;
  146.  
  147.  _asm
  148.  {
  149.   mov     [func_off],OFFSET mouse_handler
  150.   mov     [func_seg],SEG mouse_handler
  151.  }
  152.  
  153.  inregs.x.ax=0x14;
  154.  inregs.x.cx=127;
  155.  inregs.x.dx=func_off;
  156.  segs.es=func_seg;
  157.  int86x(0x33,&inregs,&outregs,&segs);
  158.  old_mouse_segment=segs.es;
  159.  old_mouse_offset=outregs.x.dx;
  160.  old_mouse_mask=outregs.x.cx;
  161. }
  162.  
  163. /****************************************************************************/
  164. /****************************************************************************/
  165. /****************************************************************************/
  166.  
  167. void remove_mouse_handler(void)
  168. {
  169.  union REGS inregs, outregs;
  170.  struct SREGS segs;
  171.  
  172.  inregs.x.ax=0x14;
  173.  inregs.x.dx=old_mouse_offset;
  174.  segs.es=old_mouse_segment;
  175.  inregs.x.cx=old_mouse_mask;
  176.  int86x(0x33,&inregs,&outregs,&segs);
  177. }
  178.  
  179. /****************************************************************************/
  180. /****************************************************************************/
  181. /****************************************************************************/
  182.  
  183. void read_mouse(void)
  184. {
  185.  union REGS inregs, outregs;
  186.  
  187.  inregs.h.ah=0;
  188.  inregs.h.al=3;
  189.  inregs.x.bx=0;
  190.  inregs.x.cx=0;
  191.  inregs.x.dx=0;
  192.  int86(0x33,&inregs,&outregs);
  193.  
  194.  mouse_x=outregs.x.cx/2;
  195.  mouse_y=outregs.x.dx;
  196.  mouse_1=(char)outregs.x.bx&0x01;
  197.  outregs.x.bx>>=1;
  198.  mouse_2=(char)outregs.x.bx&0x01;
  199.  outregs.x.bx>>=1;
  200.  mouse_3=(char)outregs.x.bx&0x01;
  201. }
  202.  
  203. /****************************************************************************/
  204. /****************************************************************************/
  205. /****************************************************************************/
  206.  
  207. void refresh_mouse(void)
  208. {
  209.  get_image(mouse_x,mouse_y,mouse_background,MOUSE_CURSOR_X_SIZE,
  210.                         MOUSE_CURSOR_Y_SIZE);
  211. }
  212.  
  213. /****************************************************************************/
  214. /****************************************************************************/
  215. /****************************************************************************/
  216.  
  217. void hide_mouse(void)
  218. {
  219.  put_image(mouse_x,mouse_y,mouse_background,MOUSE_CURSOR_X_SIZE,
  220.                          MOUSE_CURSOR_Y_SIZE,
  221.                          NORMAL);
  222. }
  223.  
  224. /****************************************************************************/
  225. /****************************************************************************/
  226. /****************************************************************************/
  227.  
  228. void show_mouse(void)
  229. {
  230.  put_image(mouse_x,mouse_y,mouse_cursor,MOUSE_CURSOR_X_SIZE,
  231.                     MOUSE_CURSOR_Y_SIZE,
  232.                     MASK);
  233. }
  234.  
  235. /****************************************************************************/
  236. /****************************************************************************/
  237. /****************************************************************************/
  238.  
  239. void update_mouse(void)
  240. {
  241.  refresh_mouse();
  242.  show_mouse();
  243. }
  244.  
  245. /****************************************************************************/
  246. /****************************************************************************/
  247. /****************************************************************************/
  248.  
  249. byte allocate_mouse(void)
  250. {
  251.  mouse_cursor=(byte huge *)halloc((long)256,1);
  252.  if (mouse_cursor==NULL)
  253.  {
  254.   printf("error allocating mouse cursor\n");
  255.   return(FAILURE);
  256.  }
  257.  mouse_background=(byte huge *)halloc((long)256,1);
  258.  if (mouse_background==NULL)
  259.  {
  260.   printf("error allocating mouse background\n");
  261.   return(FAILURE);
  262.  }
  263.  return(SUCCESS);
  264. }
  265.  
  266. /****************************************************************************/
  267. /****************************************************************************/
  268. /****************************************************************************/
  269.  
  270. void free_mouse(void)
  271. {
  272.  if (mouse_cursor!=NULL) hfree(mouse_cursor);
  273.  if (mouse_background!=NULL) hfree(mouse_background);
  274. }
  275.  
  276.